package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BaiAnswerMapper;
import com.ruoyi.system.mapper.BaiAskMapper;
import com.ruoyi.system.domain.BaiAnswer;
import com.ruoyi.system.service.IBaiAnswerService;

/**
 * 健康咨询Service业务层处理
 * 
 * @author saruri
 * @date 2024-08-18
 */
@Service
public class BaiAnswerServiceImpl implements IBaiAnswerService 
{
    @Autowired
    private BaiAnswerMapper baiAnswerMapper;

    @Autowired
    private BaiAskMapper baiAskMapper;
    /**
     * 查询健康咨询
     * 
     * @param id 健康咨询主键
     * @return 健康咨询
     */
    @Override
    public BaiAnswer selectBaiAnswerById(Long id)
    {
        return baiAnswerMapper.selectBaiAnswerById(id);
    }

    public int chose(BaiAnswer baiAnswer) {
        // 先将其他答案的状态更新为0
        baiAnswerMapper.updateStatusForOtherAnswers(baiAnswer.getAskId(), baiAnswer.getId());
        //更新问题状态为已经解决
        baiAskMapper.updateAskStatus(baiAnswer.getAskId(), 2); // 假设 3 表示问题已解决

        System.out.println("参数是ASKID:"+baiAnswer.getAskId());
        System.out.println("HUIDA参数是ASKID:"+baiAnswer.getId());
        // 然后更新当前选中的答案
        return baiAnswerMapper.choseBaiAnswer(baiAnswer);
    }

    /**
     * 查询健康咨询列表
     * 
     * @param baiAnswer 健康咨询
     * @return 健康咨询
     */
    @Override
    public List<BaiAnswer> selectBaiAnswerList(BaiAnswer baiAnswer)
    {
        return baiAnswerMapper.selectBaiAnswerList(baiAnswer);
    }

    /**
     * 新增健康咨询
     * 
     * @param baiAnswer 健康咨询
     * @return 结果
     */
    @Override
    public int insertBaiAnswer(BaiAnswer baiAnswer)
    {
        baiAnswer.setCreateTime(DateUtils.getNowDate());
        return baiAnswerMapper.insertBaiAnswer(baiAnswer);
    }

    /**
     * 修改健康咨询
     * 
     * @param baiAnswer 健康咨询
     * @return 结果
     */
    @Override
    public int updateBaiAnswer(BaiAnswer baiAnswer)
    {
        return baiAnswerMapper.updateBaiAnswer(baiAnswer);
    }

    /**
     * 批量删除健康咨询
     * 
     * @param ids 需要删除的健康咨询主键
     * @return 结果
     */
    @Override
    public int deleteBaiAnswerByIds(Long[] ids)
    {
        return baiAnswerMapper.deleteBaiAnswerByIds(ids);
    }

    /**
     * 删除健康咨询信息
     * 
     * @param id 健康咨询主键
     * @return 结果
     */
    @Override
    public int deleteBaiAnswerById(Long id)
    {
        return baiAnswerMapper.deleteBaiAnswerById(id);
    }
}
